package collections;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class Basic {
	public static void main(String[] args) {
		Collection<String> names = new ArrayList<String>();

		names.add("lion"); // adding elements to collections.
		names.add("dog");
		names.add("cat");
		names.add("");
		names.add("apple");
		System.out.println("Length:" + names.size());
		System.out.println("Length:" + names.size());
		names.add(null);
		names.add(null);
		names.add(null);
		System.out.println("Length after adding null values:  " + names.size());
		names.add("goat");
		names.add("goat");
		System.out.println("Length after adding duplicates:  " + names.size());

		Iterator<String> scan = names.iterator();
		System.out.println("The elements are:\n");

		/*
		 * By default natural ordering is NOT followed ... use Collection.sort()
		 * to get natural ordering... remove null elements in the
		 * list..(NullPointerException by sort() )
		 */
		// Collections.sort(names);
		int i = 0;
		while (scan.hasNext()) {
			i++;
			System.out.println(i + "." + scan.next());
		}

		System.out.println("Index of 1st element goat : " // index starts from 0
				+ ((ArrayList<String>) names).indexOf("lion"));
		
	     
		ArrayList<Integer> nums=new ArrayList<Integer>();
        nums.add(new Integer(1));
        nums.add(2);
	}

}
